local weidi = fk.CreateSkill{
  name = "mod__weidi",
  frequency = Skill.Compulsory,
}
local weidi_ = {
  anim_type = "special",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      if event == fk.EventPhaseStart then
        if player.phase == Player.Start and target == player then
          local cid = table.filter(Fk:getAllCardIds(), function(id)
            return (player.room:getCardArea(id) == Card.DiscardPile or player.room:getCardArea(id) == Card.DrawPile) and Fk:getCardById(id).name == "zyg__decree"
          end)
          if #cid > 0 then
            self.cost_data = cid[1]
            return true
          end
        end
      elseif event == fk.GameStart then
        return true
      else
        return data.lordSkill and not player:hasSkill(data, true) and target.role == "lord"
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.EventPhaseStart then
      return player.room:askForDiscard(player, 2, 2, true, self.name, true, nil, "weidi_ask")
    else
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local skills = {}
    local lord = room:getLord()
    if event == fk.EventPhaseStart then
      local card = self.cost_data
      room:obtainCard(player.id, card, true, fk.ReasonJustMove)
    else
      if event == fk.GameStart then 
        for _, p in ipairs(room.alive_players) do
          if p ~= player and p.role == "lord" then
            for _, s in ipairs(p.player_skills) do
              if s.lordSkill and not player:hasSkill(s, true)  then
                table.insert(skills, s.name)
              end
            end
          end
        end
      else
        table.insert(skills, data.name)
      end
      if #skills > 0 then
        room:handleAddLoseSkills(player, table.concat(skills, "|"), nil)
      end
      if (#skills == 0 or lord == player) and player:hasEmptyEquipSlot(Card.SubtypeTreasure) then
        for _, id in ipairs(Fk:getAllCardIds()) do
          if Fk:getCardById(id).name == "zyg__decree" then
            room:moveCardIntoEquip(player, id, self.name)
            break
          end
        end
      end
    end
  end,
}
weidi:addEffect(fk.GameStart, weidi_)
weidi:addEffect(fk.EventAcquireSkill, weidi_)
weidi:addEffect(fk.EventPhaseStart, weidi_)
return weidi